package com.chunxuan.langquan.ui.activity.store;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.blankj.utilcode.util.GsonUtils;
import com.chunxuan.langquan.R;
import com.chunxuan.langquan.base.Base2Activity;
import com.chunxuan.langquan.base.BaseResult2;
import com.chunxuan.langquan.base.Global;
import com.chunxuan.langquan.dao.bean.CarProductEntity;
import com.chunxuan.langquan.dao.bean.ProductEntity;
import com.chunxuan.langquan.dao.http.APIRetrofit;
import com.chunxuan.langquan.support.util.GlideUtil;
import com.chunxuan.langquan.support.util.Logg;
import com.chunxuan.langquan.ui.activity.store.adapter.BaseAdapter;
import com.chunxuan.langquan.ui.activity.store.adapter.BaseViewHolder;
import com.ruitu.arad.api.RxUtil;
import com.ruitu.arad.util.ToastUtils;
import com.ruitu.arad.util.UIUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.Locale;

import io.reactivex.disposables.Disposable;
import io.reactivex.functions.Consumer;

public class ShoppingCarActivity extends Base2Activity {

    private RecyclerView rlv;
    private RecyclerView rlvProduct;
    private Adapter mAdapter;
    private ProductAdapter mProductAdapter;
    private RelativeLayout rlRecommended;
    private TextView tvAllPrice;
    private ImageView ivBack;
    private LinearLayout llCheckAll;
    private ImageView ivCheckAll;
    private ImageView ivNoCheckAll;
    private TextView tvEdit;
    private TextView tvEditOk;
    private TextView tvDelete;
    private TextView tvOrders;
    private TextView tvDetail;
    private LinearLayout llDetail;

    @Override
    protected int getLayoutRes() {
        return R.layout.activity_store_shopcar;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        initView();
    }

    public void initView() {
        rlv = findViewById(R.id.rlv_car_product);
        rlvProduct = findViewById(R.id.rlv_product);
        rlRecommended = findViewById(R.id.rl_recommended);
        tvAllPrice = findViewById(R.id.tv_all_price);
        llCheckAll = findViewById(R.id.ll_check_all);
        ivCheckAll = findViewById(R.id.iv_check);
        ivNoCheckAll = findViewById(R.id.iv_no_check);
        tvEdit = findViewById(R.id.tv_edit);
        tvEditOk = findViewById(R.id.tv_edit_ok);
        ivBack = findViewById(R.id.iv_back);
        tvDelete = findViewById(R.id.tv_delete);
        tvOrders = findViewById(R.id.tv_pay);
        tvDetail = findViewById(R.id.tv_detail);
        llDetail = findViewById(R.id.ll_detail);
        mAdapter = new Adapter(this);

        mProductAdapter = new ProductAdapter(this);
        RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(this);
        rlv.setLayoutManager(layoutManager);
        RecyclerView.LayoutManager layoutManager1 = new GridLayoutManager(this, 2);
        rlvProduct.setLayoutManager(layoutManager1);
        rlv.setAdapter(mAdapter);
        rlv.getRecycledViewPool().setMaxRecycledViews(0, 0);
        rlvProduct.setAdapter(mProductAdapter);
        requestCarProducts();
        requestRecommendedProducts();
        ivBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        llDetail.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                showDetail();
            }
        });

        tvEdit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                tvEdit.setVisibility(View.INVISIBLE);
                tvEditOk.setVisibility(View.VISIBLE);
                tvOrders.setVisibility(View.INVISIBLE);
                tvDelete.setVisibility(View.VISIBLE);
                tvDelete.setText("删除(" + getDeleteCount() + ")");

            }
        });


        tvEditOk.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                tvEdit.setVisibility(View.VISIBLE);
                tvEditOk.setVisibility(View.INVISIBLE);
                tvOrders.setVisibility(View.VISIBLE);
                tvDelete.setVisibility(View.INVISIBLE);
            }
        });

        tvDelete.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                StringBuilder sb = new StringBuilder();
                for (int i = 0; i < mAdapter.getDatas().size(); i++) {
                    CarProductEntity entity = mAdapter.getDatas().get(i);
                    if (entity.getChoose() == 1) {

                        sb.append(mAdapter.getDatas().get(i).getCart_id()).append(",");
                    }
                }
                if (sb.toString().equals("")) {
                    ToastUtils.showShort("请选择商品");
                    return;
                }
                DeleteEnsureDialog ensureDialog = new DeleteEnsureDialog();

                Bundle bundle = new Bundle();
                bundle.putString("id", sb.toString());
                ensureDialog.setArguments(bundle);
                ensureDialog.show(getSupportFragmentManager(), "");
            }
        });
        tvOrders.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                requestOrder();
            }
        });

    }

    /** 获取选中的个数 */
    public int getDeleteCount() {
        int count = 0;
        for (int i = 0; i < mAdapter.getDatas().size(); i++) {
            CarProductEntity entity = mAdapter.getDatas().get(i);
            if (entity.getChoose() == 1) {
                count++;
            }

        }
        return count;
    }

    public void setCheckViewStatus(boolean isChecked) {
        if (isChecked) {
            ivNoCheckAll.setVisibility(View.GONE);
            ivCheckAll.setVisibility(View.VISIBLE);
        } else {
            ivNoCheckAll.setVisibility(View.VISIBLE);
            ivCheckAll.setVisibility(View.GONE);
        }
    }

    public void showDetail() {
        View view = View.inflate(this, R.layout.pop_store_detail, null);
        TextView tvAllPrice = view.findViewById(R.id.tv_all_price_ll);
        TextView tvTotalPrice = view.findViewById(R.id.tv_total_price_actually);
        RelativeLayout rlDiscount = view.findViewById(R.id.rl_discount);
        tvAllPrice.setText("￥" + mAdapter.getTotalPrice());
        if (mAdapter.getTotalPrice() > 10) {
            rlDiscount.setVisibility(View.VISIBLE);
            tvTotalPrice.setText("合计  ￥" + (mAdapter.getTotalPrice() - 5));
        } else {
            rlDiscount.setVisibility(View.INVISIBLE);
            tvTotalPrice.setText("合计  ￥" + (mAdapter.getTotalPrice()));

        }
        PopupWindow popWindow = new PopupWindow(view, ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.WRAP_CONTENT, true);
        popWindow.setOutsideTouchable(true);
        popWindow.setAnimationStyle(R.style.popupwindow_anim_style);
        popWindow.showAtLocation(getWindow().getDecorView(), Gravity.BOTTOM, 0, UIUtils.convertDpToPixel(this,
                50));
    }

    /**
     * 下单
     */
    public void requestOrder() {
        List<CarProductEntity> list = new ArrayList<>();
        for (int i = 0; i < mAdapter.getDatas().size(); i++) {
            if (mAdapter.getDatas().get(i).getChoose() == 1) {
                list.add(mAdapter.getDatas().get(i));
            }
        }
        if (list.size() == 0) {
            ToastUtils.showShort("没有选中商品");
            return;
        }
        Intent intent = new Intent(this, OrdersActivity.class);

        intent.putExtra("data", GsonUtils.toJson(list));
        startActivity(intent);
    }

    public Disposable requestCarProducts() {
        return APIRetrofit.getDefault().requestCarProducts(Global.HEADER)
                .compose(RxUtil.<BaseResult2<List<CarProductEntity>>>subIoObMain())
                .subscribe(new Consumer<BaseResult2<List<CarProductEntity>>>() {
                    @Override
                    public void accept(BaseResult2<List<CarProductEntity>> result2) throws Exception {
                        hideProgress();
                        if (result2.isSuccess()) {
                            final List<CarProductEntity> categorys = result2.getData();
                            if (!isDataEmpty(categorys)) {
                                Logg.e("==购物车列表==" + categorys.get(0));
                                mAdapter.setDatas(categorys);
                                mAdapter.updatePrice();
                                if (mAdapter.isCheckAll()) {
                                    setCheckViewStatus(true);
                                } else {
                                    setCheckViewStatus(false);
                                }
                                llCheckAll.setOnClickListener(new View.OnClickListener() {
                                    @Override
                                    public void onClick(View view) {
                                        boolean isAllChecked = true;
                                        for (int i = 0; i < categorys.size(); i++) {
                                            if (categorys.get(i).getChoose() == 0) {
                                                isAllChecked = false;
                                                break;
                                            }
                                        }
                                        // 已经全部选中
                                        if (isAllChecked) {
                                            StringBuilder sb = new StringBuilder();
                                            for (int i = 0; i < mAdapter.getDatas().size(); i++) {
                                                sb.append(mAdapter.getDatas().get(i).getCart_id()).append(",");
                                            }
                                            alterProductStatus("", sb.toString(), false);
                                        } else {
                                            StringBuilder sb = new StringBuilder();
                                            for (int i = 0; i < mAdapter.getDatas().size(); i++) {
                                                sb.append(mAdapter.getDatas().get(i).getCart_id()).append(",");
                                            }
                                            alterProductStatus(sb.toString(), "", true);
                                        }
                                    }
                                });

                            }else{
                                mAdapter.setDatas(categorys);
                                mAdapter.updatePrice();
                            }
                        } else {
                            ToastUtils.showShort(result2.getMsg());
                        }
//                        Logg.i("reqUserInfo.result2.getMsg()" + result2.getMsg());
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        hideProgress();
                        throwable.printStackTrace();
                        ToastUtils.showShort("获取全部类型失败");
                    }
                });
    }

    @SuppressLint("CheckResult")
    public void alterProductStatus(String checkedId, String noCheckedId, final boolean isChecked) {
        APIRetrofit.getDefault().alterProductStatus(Global.HEADER, checkedId,
                noCheckedId)
                .compose(RxUtil.<BaseResult2<String>>subIoObMain())
                .subscribe(new Consumer<BaseResult2<String>>() {
                    @Override
                    public void accept(BaseResult2<String> result2) throws Exception {

                        if (result2.isSuccess()) {
//                                        viewHolder.tvNum.setText(result2.getData());
//                                        entity.setNumber(Integer.parseInt(result2.getData()));
//                                        updatePrice();
                            if (isChecked) {
                                setCheckViewStatus(true);
                            } else {
                                setCheckViewStatus(false);
                            }
                            requestCarProducts();
                        } else {
                            ToastUtils.showShort(result2.getMsg());
                        }
                        Logg.i("reqUserInfo.result2.getMsg()" + result2.getMsg());
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        throwable.printStackTrace();
                        ToastUtils.showShort("修改状态失败");
                    }
                });
    }


    public Disposable requestRecommendedProducts() {
        return APIRetrofit.getDefault().requestRecommenedProductList(Global.HEADER)
                .compose(RxUtil.<BaseResult2<List<ProductEntity>>>subIoObMain())
                .subscribe(new Consumer<BaseResult2<List<ProductEntity>>>() {
                    @Override
                    public void accept(BaseResult2<List<ProductEntity>> result2) throws Exception {
                        hideProgress();
                        if (result2.isSuccess()) {
                            List<ProductEntity> categorys = result2.getData();
                            if (!isDataEmpty(categorys)) {
                                rlRecommended.setVisibility(View.VISIBLE);
                                Logg.e("==推荐列表==" + categorys.get(0));
                                mProductAdapter.setDatas(categorys);

                            }
                        } else {
                            ToastUtils.showShort(result2.getMsg());
                        }
//                        Logg.i("reqUserInfo.result2.getMsg()" + result2.getMsg());
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        hideProgress();
                        throwable.printStackTrace();
                        ToastUtils.showShort("获取推荐列表");
                    }
                });
    }

    @SuppressLint("DefaultLocale")
    public void updateData(float price) {
        if (price > 10) {
            tvAllPrice.setText(String.format("合计：￥%.2f", price - 5));
            tvDetail.setText("共节省￥5   明细");
        } else {
            tvAllPrice.setText(String.format("合计：￥%.2f", price));
            tvDetail.setText("共节省￥0   明细");

        }
        tvDelete.setText("删除(" + getDeleteCount() + ")");

    }

    static class Adapter extends BaseAdapter<CarProductEntity> {

        ShoppingCarActivity activity;

        public Adapter(ShoppingCarActivity activity) {
            this.activity = activity;
        }

        @NonNull
        @Override
        public BaseViewHolder<CarProductEntity> onCreateViewHolder(@NonNull ViewGroup parent,
                                                                   int viewType) {
            LayoutInflater layoutInflater = LayoutInflater.from(parent.getContext());
            View view = layoutInflater.inflate(R.layout.item_rlv_store_shoppingcar, parent, false);
            final ViewHolder viewHolder = new ViewHolder(view);

            viewHolder.tvAdd.setOnClickListener(new View.OnClickListener() {
                @SuppressLint("CheckResult")
                @Override
                public void onClick(View v) {
                    final CarProductEntity entity = getDatas().get(viewHolder.getAdapterPosition());
                    int num = Integer.parseInt(viewHolder.tvNum.getText().toString());
                    APIRetrofit.getDefault().alterProductNum(Global.HEADER,
                            entity.getCart_id() + "", num + 1)
                            .compose(RxUtil.<BaseResult2<String>>subIoObMain())
                            .subscribe(new Consumer<BaseResult2<String>>() {
                                @Override
                                public void accept(BaseResult2<String> result2) throws Exception {

                                    if (result2.isSuccess()) {
                                        viewHolder.tvNum.setText(result2.getData());
                                        entity.setNumber(Integer.parseInt(result2.getData()));
                                        updatePrice();
                                    } else {
                                        ToastUtils.showShort(result2.getMsg());
                                    }
                                    Logg.i("reqUserInfo.result2.getMsg()" + result2.getMsg());
                                }
                            }, new Consumer<Throwable>() {
                                @Override
                                public void accept(Throwable throwable) throws Exception {
                                    throwable.printStackTrace();
                                    ToastUtils.showShort("修改数量失败");
                                }
                            });

                }
            });
            viewHolder.tvSubtract.setOnClickListener(new View.OnClickListener() {
                @SuppressLint("CheckResult")
                @Override
                public void onClick(View view) {
                    final CarProductEntity entity = getDatas().get(viewHolder.getAdapterPosition());
                    int num = Integer.parseInt(viewHolder.tvNum.getText().toString());
                    if (num == 1) {
                        return;
                    }
                    APIRetrofit.getDefault().alterProductNum(Global.HEADER,
                            entity.getCart_id() + "", num - 1)
                            .compose(RxUtil.<BaseResult2<String>>subIoObMain())
                            .subscribe(new Consumer<BaseResult2<String>>() {
                                @Override
                                public void accept(BaseResult2<String> result2) throws Exception {

                                    if (result2.isSuccess()) {
                                        viewHolder.tvNum.setText(result2.getData());
                                        entity.setNumber(Integer.parseInt(result2.getData()));
                                        updatePrice();
                                    } else {
                                        ToastUtils.showShort(result2.getMsg());
                                    }
                                    Logg.i("reqUserInfo.result2.getMsg()" + result2.getMsg());
                                }
                            }, new Consumer<Throwable>() {
                                @Override
                                public void accept(Throwable throwable) throws Exception {
                                    throwable.printStackTrace();
                                    ToastUtils.showShort("修改数量失败");
                                }
                            });
                }
            });
            viewHolder.ivCheck.setOnClickListener(new View.OnClickListener() {
                @SuppressLint("CheckResult")
                @Override
                public void onClick(View view) {
                    viewHolder.ivCheck.setVisibility(View.INVISIBLE);
                    viewHolder.ivNoCheck.setVisibility(View.VISIBLE);
                    activity.setCheckViewStatus(false);
                    final CarProductEntity entity = getDatas().get(viewHolder.getAdapterPosition());
                    entity.setChoose(0);
                    updatePrice();

                    APIRetrofit.getDefault().alterProductStatus(Global.HEADER, "",
                            entity.getCart_id() + "")
                            .compose(RxUtil.<BaseResult2<String>>subIoObMain())
                            .subscribe(new Consumer<BaseResult2<String>>() {
                                @Override
                                public void accept(BaseResult2<String> result2) throws Exception {

                                    if (result2.isSuccess()) {
//                                        viewHolder.tvNum.setText(result2.getData());
//                                        entity.setNumber(Integer.parseInt(result2.getData()));
//                                        updatePrice();
                                    } else {
                                        ToastUtils.showShort(result2.getMsg());
                                    }
                                    Logg.i("reqUserInfo.result2.getMsg()" + result2.getMsg());
                                }
                            }, new Consumer<Throwable>() {
                                @Override
                                public void accept(Throwable throwable) throws Exception {
                                    throwable.printStackTrace();
                                    ToastUtils.showShort("修改状态失败");
                                }
                            });

                }
            });

            viewHolder.ivNoCheck.setOnClickListener(new View.OnClickListener() {
                @SuppressLint("CheckResult")
                @Override
                public void onClick(View view) {
                    viewHolder.ivNoCheck.setVisibility(View.INVISIBLE);
                    viewHolder.ivCheck.setVisibility(View.VISIBLE);
                    final CarProductEntity entity = getDatas().get(viewHolder.getAdapterPosition());
                    entity.setChoose(1);
                    updatePrice();

                    APIRetrofit.getDefault().alterProductStatus(Global.HEADER,
                            entity.getCart_id() + "", "")
                            .compose(RxUtil.<BaseResult2<String>>subIoObMain())
                            .subscribe(new Consumer<BaseResult2<String>>() {
                                @Override
                                public void accept(BaseResult2<String> result2) throws Exception {

                                    if (result2.isSuccess()) {
//                                        viewHolder.tvNum.setText(result2.getData());
//                                        entity.setNumber(Integer.parseInt(result2.getData()));
//                                        updatePrice();

                                    } else {
                                        ToastUtils.showShort(result2.getMsg());
                                    }
                                    Logg.i("reqUserInfo.result2.getMsg()" + result2.getMsg());
                                }
                            }, new Consumer<Throwable>() {
                                @Override
                                public void accept(Throwable throwable) throws Exception {
                                    throwable.printStackTrace();
                                    ToastUtils.showShort("修改状态失败");
                                }
                            });
                    if (isCheckAll()) {
                        activity.setCheckViewStatus(true);
                    }
                }
            });
            return viewHolder;
        }

        public void updatePrice() {


            float allPrice = 0;
            for (int i = 0; i < getDatas().size(); i++) {
                allPrice = (getDatas().get(i).getChoose() == 1) ?
                        allPrice + (getDatas().get(i).getNumber() * getDatas().get(i).getSales_price()) : allPrice;
            }
            activity.updateData(allPrice);
        }

        public float getTotalPrice() {
            float allPrice = 0;
            for (int i = 0; i < getDatas().size(); i++) {
                allPrice = (getDatas().get(i).getChoose() == 1) ?
                        allPrice + (getDatas().get(i).getNumber() * getDatas().get(i).getSales_price()) : allPrice;
            }
            return allPrice;
        }

        public boolean isCheckAll() {
            for (int i = 0; i < getDatas().size(); i++) {
                if (getDatas().get(i).getChoose() == 0) {
                    return false;
                }
            }
            return true;
        }
    }

    static class ViewHolder extends BaseViewHolder<CarProductEntity> {
        ImageView iv;
        ImageView ivCheck;
        ImageView ivNoCheck;
        TextView tvTitle;
        TextView tvPrice;
        TextView tvAdd;
        TextView tvSubtract;
        TextView tvNum;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            iv = itemView.findViewById(R.id.iv_img);
            ivCheck = itemView.findViewById(R.id.iv_check);
            tvTitle = itemView.findViewById(R.id.tv_title);
            tvPrice = itemView.findViewById(R.id.tv_price);
            tvAdd = itemView.findViewById(R.id.tv_add);
            tvSubtract = itemView.findViewById(R.id.tv_subtract);
            tvNum = itemView.findViewById(R.id.tv_num);
            ivNoCheck = itemView.findViewById(R.id.iv_no_check);
        }

        @Override
        public void bindViewHolder(CarProductEntity value) {
            GlideUtil.loadImg(value.getImage(), iv);
            tvTitle.setText(value.getTitle());
            tvPrice.setText(String.format(Locale.CHINA, "￥%.2f", value.getSales_price()));
            tvNum.setText(value.getNumber() + "");
            if (value.getChoose() == 1) {
                ivCheck.setVisibility(View.VISIBLE);
                ivNoCheck.setVisibility(View.INVISIBLE);
            } else {
                ivCheck.setVisibility(View.INVISIBLE);
                ivNoCheck.setVisibility(View.VISIBLE);
            }

        }
    }

    static class ProductAdapter extends BaseAdapter<ProductEntity> {

        ShoppingCarActivity mShoppingCarActivity;

        public ProductAdapter(ShoppingCarActivity activity) {
            this.mShoppingCarActivity = activity;
        }

        @NonNull
        @Override
        public BaseViewHolder<ProductEntity> onCreateViewHolder(@NonNull ViewGroup parent,
                                                                int viewType) {
            LayoutInflater layoutInflater = LayoutInflater.from(parent.getContext());
            View view = layoutInflater.inflate(R.layout.item_product_sub_list, parent, false);
            final ProductViewHolder viewHolder = new ProductViewHolder(view);
            viewHolder.tvAddCar.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    ProductEntity entity = getDatas().get(viewHolder.getAdapterPosition());
                    requestAddProduct(entity.getProduct_id());
                }
            });
            viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    ProductEntity entity = getDatas().get(viewHolder.getAdapterPosition());
                    ProductDetailActivity.actionStart(mShoppingCarActivity, entity.getProduct_id());
                }
            });
            return viewHolder;
        }

        @SuppressLint("CheckResult")
        public void requestAddProduct(String id) {
            APIRetrofit.getDefault().addProduct(Global.HEADER, id)
                    .compose(RxUtil.<BaseResult2<String>>subIoObMain())
                    .subscribe(new Consumer<BaseResult2<String>>() {
                        @Override
                        public void accept(BaseResult2<String> result2) throws Exception {
                            if (result2.isSuccess()) {
                                mShoppingCarActivity.requestCarProducts();
//                                ToastUtils.showShort(result2.getMsg());
                            } else {
                                ToastUtils.showShort(result2.getMsg());
                            }
//                        Logg.i("reqUserInfo.result2.getMsg()" + result2.getMsg());
                        }
                    }, new Consumer<Throwable>() {
                        @Override
                        public void accept(Throwable throwable) throws Exception {

                            throwable.printStackTrace();
                            ToastUtils.showShort("添加商品失败");
                        }
                    });
        }
    }

    static class ProductViewHolder extends BaseViewHolder<ProductEntity> {
        ImageView iv;
        TextView tvTitle;
        TextView tvPrice;
        TextView tvAddCar;

        public ProductViewHolder(@NonNull View itemView) {
            super(itemView);
            iv = itemView.findViewById(R.id.iv_product_list_cover);
            tvTitle = itemView.findViewById(R.id.tv_product_list_price);
            tvPrice = itemView.findViewById(R.id.tv_product_list_name);
            tvAddCar = itemView.findViewById(R.id.tv_product_purchase_now);
        }

        @Override
        public void bindViewHolder(ProductEntity value) {
            GlideUtil.loadImg(value.getImage(), iv);
            tvTitle.setText(value.getTitle());
            tvPrice.setText(value.getSales_price());
        }
    }
}